﻿
using Sustainalytics.Alerts.AlertsEngine;
using Sustainalytics.DataLayer.ConnectionStrings;
using Sustainalytics.Entities;
using Sustainalytics.Utils;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.Dispatcher;

namespace Sustainalytics.Alerts.Service
{
    public class AlertsHelper
    {

        private readonly DeploymentLocation deploymentLocation;
        public void Start()
        {
               
            var config = new HttpConfiguration();

            config.Filters.Add(new LogControllerFilter(true, true, false));

            var container = CompositionRoot.RegisterDependencies(config);

            config.Services.Replace(typeof(IHttpControllerActivator), new SimpleInjectorControllerActivator(container));

            AlertsEngine.AlertsEngine.GetAlertsEngine(deploymentLocation, 
                container.GetInstance<IBlobHelper>(), 
                container.GetInstance<IAlertsSubscription>(), 
                container.GetInstance<IAlertsManager>(), 
                container.GetInstance<IConnectionStringsManager>(), 
                ConfigurationManager.ConnectionStrings["ClientPlatform"].ToString(),
                container.GetInstance<IPorfolioNamesCache>(),
                container.GetInstance<IPortfolioCompanyCache>(),
                container.GetInstance<IFeatureUniversesCache>())
                   .StartAlertsTimer();
            
        }

    }
}
